package org.lds.scheduled.job.common.util;

import lombok.extern.slf4j.Slf4j;
import org.lds.scheduled.job.common.enums.ErrorEnum;
import org.lds.scheduled.job.common.exception.BusinessException;
import org.lds.scheduled.job.common.exception.ExceptionMessage;

@Slf4j
public class ExceptionUtil {
    public static ExceptionMessage errorMessage(Throwable e) {
        if (e instanceof BusinessException) {
            return ((BusinessException) e).getExceptionMessage();
        }

        log.error("errorMessage. cause={}", e.getMessage());
        ErrorEnum errorEnum = ErrorEnum.SYSTEM_ERROR;
        return new ExceptionMessage(errorEnum.getErrCode(), errorEnum.getErrMsg());
    }
}
